<?php
namespace app\admin\validate;
use think\Validate;
use think\Db;
class CouPonEdit extends Validate
{

    // 验证规则
    protected $rule = [
        'id'              =>'checkAId',
        'cname'            => 'require|min:1|max:150'
    ];
    //错误信息
    protected $message  = [
        'cname.require'                            => '名称必填',
        'cname.min'                                => '名称长度至少1个字符',
        'cname.max'                                => '名称长度至多50个汉字',
        'cname.unique'                             => '名字重复'
    ];
	
	
	//等于和不等于
	public function checkooo($data, $rules = [], $scene = '')
    {
    	$id = input('id/d',0);
    	$cnamestr = 'require|min:1|max:150|unique:coupon';
    	if($id>0){
    		$cnamestr = 'require|min:1|max:150|unique:coupon,cname,'.$id.',id';
    	}
    	
    	$this->rule = [
	        'id'              =>'checkAId',
	        'cname'           => $cnamestr
	    ];
	    
	    $this->message  = [
	        'cname.require'                            => '名称必填',
	        'cname.min'                                => '名称长度至少1个字符',
	        'cname.max'                                => '名称长度至多50个汉字',
	        'cname.unique'                             => '名字重复'
	    ];
		
		return parent::check($data);
    }

    /**
     * 检查是否有商品规格参加活动，若有则不能编辑商品
     * @param $value
     * @return bool
     */
    protected function checkAId($value){
        return true;
    }

}